package com.lizardmind.haofudoctor.ui.aboutMe.set

import android.os.Bundle
import android.view.View
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ActivityChangePassword2Binding
import com.lizardmind.haofudoctor.manager.postApi
import com.lizardmind.haofudoctor.other.DoctorInfo
import com.lizardmind.haofudoctor.other.Request
import com.lizardmind.haofudoctor.other.checkPassWord
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.include_title_text.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.toast

/**
 * Created by Administrator on 2017/10/27.
 * 设置新密码activity
 */
class ChangePasswordActivity2: BaseActivity() {

    val binding by lazy { getDataBinding<ActivityChangePassword2Binding>(R.layout.activity_change_password2) }
    override fun onCreatRootView(): View {
        return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {

        title.apply {
            titleText.text="修改密码"
            imgLeft.setImageResource(R.mipmap.back)
            imgLeft.setOnClickListener{ finish() }
        }

        binding.apply {
            newPass=false
            newPassWord=""

            tvChangePasswordOK.onClick {
                if(checkPassWord(newPassWord!!)){
                    observe {
                        postApi<Request<String>>(hashMapOf("action" to "doctor_edit_pword",
                                "token" to DoctorInfo.token,
                                "type" to "3",
                                "newpword" to newPassWord!!),
                                Consumer {
                                    it.dispose {
                                        toast(it)
                                        finish()
                                    }
                                })
                    }
                }else{
                    toast("密码格式为数字、字母组成")
                }
            }
        }

    }
}